<?php

defined('PHPFOX') or exit('NO DICE!');
 
class User_Service_Abstractcart extends Phpfox_Service 
{
		
		/*
			CAN OPEN A STORE? 
		*/
		public function getStorePermissions($aParams=null){ 
			
			//$aParams['user_id']
			
				//Auctions  
				if(Phpfox::isModule('abstractauction')){ 
					
					//Can users sell Auctions? (check Auction config) 
					$oAucConfig = Phpfox::getService('abstractauction.config');
					$aAucCon = $oAucConfig->getConfig();
					if($aAucCon['require_module'] == 0){ 
					
						//Can this $aGroup['user_id'] usergroup sell Auctions? (check with auction module) 
						$oAuctionsUsers = Phpfox::getService('abstractauction.users');
						
						//Get All User Data  
						$aUserDataParams['iUserId'] = $aParams['user_id'];
						$aUserDataParams['sPlanData'] = 'submit'; //submit, access, both, none 
						$aUserDataParams['bSettings'] = true;
						$aUserDataParams['bSystemData'] = true;
						$aUserDataParams['bSystemUsergroupData'] = false;
						$aUserDataParams['bCountAuctions'] = true;
						//$aUserDataParams['bCounts'] = true;
						$aUser = $oAuctionsUsers->getUserData($aUserDataParams);
						
						//Usergroup Can Submit  
						if(isset($aUser['aSubmit']['plans_submit_id'])){ return true; }
					
					}
				}
			
		return false;
		}
		
		public function getStorePermission($aParams=null){ 
		
			$aItem = $this->getItem($aParams);
			
			$aTypesArray = array();
			
			if(!$aItem){ 
				return false;
			}else{ 
				
				//Does this user own this Group? 
				if($aItem['user_id'] != $aParams['user_id']){ return false; }
				
				//Auctions  
				if(Phpfox::isModule('abstractauction')){ 
					
					//Can users sell Auctions? (check Auction config) 
					$oAucConfig = Phpfox::getService('abstractauction.config');
					$aAucCon = $oAucConfig->getConfig();
					if($aAucCon['require_module'] == 0){ 
					
						//Can this $aGroup['user_id'] usergroup sell Auctions? (check with auction module) 
						$oAuctionsUsers = Phpfox::getService('abstractauction.users');
						
						//Get All User Data  
						$aUserDataParams['iUserId'] = $aItem['user_id'];
						$aUserDataParams['sPlanData'] = 'submit'; //submit, access, both, none 
						$aUserDataParams['bSettings'] = true;
						$aUserDataParams['bSystemData'] = true;
						$aUserDataParams['bSystemUsergroupData'] = false;
						$aUserDataParams['bCountAuctions'] = true;
						//$aUserDataParams['bCounts'] = true;
						$aUser = $oAuctionsUsers->getUserData($aUserDataParams);
						
						//Usergroup Can Submit  
						if($aParams['sFormat'] == 'boolean'){
							if(isset($aUser['aSubmit']['plans_submit_id'])){ return true; }
						}else{ 
							if(isset($aUser['aSubmit']['plans_submit_id'])){ 
								
								$aTypesArray[] = 'auctions';
								if($aAucCon['events_can'] == 1){ $aTypesArray[] = 'events'; }
								 
							}
						}
						
						//Can this module usergroup sell Auctions? (not applicable to groups, but in business we check if this businss plan can submit auctions) 
					
					}
				}
				
				//Music 
				
					//Can groups sell Music 
				
					//Can this user's usergroup sell Music? 
				
				
				
				if($aParams['sFormat'] == 'boolean'){
					return false;
				}else{
					return $aTypesArray;
				}
			}
			
		}
		
		
		/*
		*	GET ITEM  
		*/
		public function getItem($aParams=null)
		{
			if($aParams['module_item_type'] == 0){
				
				//$aUser = Phpfox::getService('user')->getUser($aParams['module_item_id'], 'u.*');
				$aUser = Phpfox::getService('user')->get($aParams['module_item_id'], true);
				
				if (!isset($aUser['user_id']))
				{
					return false;
				}
				
				$aUser['location'] = Phpfox::getService('core.country')->getCountry($aUser['country_iso']);
				
				if (!empty($aUser['city_location'])){
					$sCity = Phpfox::getLib('parse.output')->clean($aUser['city_location']);
				}else{ 
					$sCity = '';
				}
				
				if ($aUser['country_child_id'] > 0){
					$sState = Phpfox::getService('core.country')->getChild($aUser['country_child_id']);
				}else{ 
					$sState = '';
				}
				
				if (!empty($aUser['country_iso'])){
					$sCountry = Phpfox::getPhraseT($aUser['location'], 'country');
				}else{ 
					$sCountry = '';
				}
				
				if (isset($aUser['postal_code'])){
					$sZipcode = $aUser['postal_code'];
				}else{ 
					$sZipcode = '';
				}
				//print_r($aUser);
				
				//Custom Theme 
				$iStyleId = 0; 
				if(isset($aUser['designer_style_id']) && $aUser['designer_style_id'] > 0){ 
					$iStyleId = $aUser['designer_style_id']; 
				}
				
				return array( 
				
					'title' 			=> $aUser['full_name'], 
					'url-name' 			=> $aUser['user_name'], 
					'user_id' 			=> $aUser['user_id'], 
					'url' 				=> Phpfox::getLib('url')->makeUrl($aUser['user_name']),
					'url-products' 		=> Phpfox::getLib('url')->makeUrl($aUser['user_name'].'.abstractstore'), 
					'url-auctions' 		=> Phpfox::getLib('url')->makeUrl($aUser['user_name'].'.abstractauction'), 
					'image' 			=> '',
					'image-large' 		=> '',
					
					'text'				=> '',
					'text-long'			=> '',	
						
					'country'			=> $sCountry,	
					'state'				=> $sState,	
					'city'				=> $sCity,	
					'zip'				=> $sZipcode,	
					'street'			=> '',	
					'phone'				=> '',	
					'email'				=> $aUser['email'],		
					'website'			=> '',
					
					'style_id' 			=> $iStyleId, 
				);
			}
			
		return false;
		}

}
?>